package com.woniuxy.threeproject.end_water_project_user.commons;

import com.woniuxy.threeproject.end_water_project_user.domain.Account;
import com.woniuxy.threeproject.end_water_project_user.domain.User;
import com.woniuxy.threeproject.end_water_project_user.domain.Watermeter;
import lombok.extern.slf4j.Slf4j;

import java.util.Date;
import java.util.Random;
@Slf4j
public class AccountAndWaterMeter {

    public static Account getAccount(){
// ----------------新增账号表------------------------
//        得到账户id，要获取表
        //新建账户表，新建账号
        String account = new Random().nextInt(1000000)+"";
        long account1 = Long.parseLong(account);
        String password="123456";//默认账户密码为123456
        int Grade=0;//默认普通用户
        String state="0"; //默认状态为正常
        Account ac = new Account();
        ac.setPassword(password);
        ac.setAccount(account1);
        ac.setGrade(0);//普通用户
        ac.setState("0"); //正常状态
       log.info("开始新增账户表{}",new Date());
      return  ac;
    }

    public static Watermeter getWaterMeter(){
        log.info("开始注册管道水表id");
        Watermeter wm = new Watermeter();
//        水表id自动增长，不用管
        //   水表型号,随机生成一个

        String[] strs = new String[]{"s001","s002","s003"};
        int i = new Random().nextInt(strs.length-1);
        Double[] d =new Double[]{5.0,10.0,15.0};
        // 水表型号
        String waterMeterType=strs[i];
        //管道型号
        Double pipeDiameter=d[i];
        //材质，默认是塑料
        String pipeMaterial=new String("塑料".getBytes());
        //水表品牌
        String [] brands=new String[]{"蜗牛牌","黑马牌","传智播客牌"};
        String waterMeterBrand=brands[i];
        wm.setPipeDiameter(pipeDiameter);
        wm.setPipeMaterial(pipeMaterial);
        wm.setWaterMeterBrand(waterMeterBrand);
        wm.setWaterMeterType(waterMeterType);
        return wm;
    }

    public static User getUser(String name,String address,String idCard,Long phone){
        int n = new Random().nextInt(1000);
        String card=UUIDUtils.getUUid().toString().replace("-","").substring(0,4)+n;
//        Account reac = getAccount();
//        Watermeter rewater = getWaterMeter();
//        Integer accountId=reac.getAccountId();
//        Integer waterMeterId=rewater.getWaterMeterId();
        User u = new User();
        u.setUserName(name);
        u.setAddress(address);
        u.setPhone(phone);
        u.setIdCard(idCard);
        u.setCard(card);
//        u.setWaterMeterId(waterMeterId);
//        u.setAccountId(accountId);
        return u;
    }


}
